package com.example.project.Service.Impl;

import com.example.project.Dao.BlogDao;
import com.example.project.Dao.CommentDao;
import com.example.project.Entity.Comment;
import com.example.project.Service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentDao commentDao;

    @Autowired
    private BlogDao blogDao;

    @Override
    public void saveComment(Comment comment){
        commentDao.saveComment(comment);
        blogDao.addCommentsNumber(comment.getBlog_id());
    }

    @Override
    public List<Comment> selectCommentByBlog(int blog_id){
        return commentDao.selectCommentByBlog(blog_id);
    }

    @Override
    public void deleteComment(int comment_id, int blog_id){
        commentDao.deleteComment(comment_id);
        blogDao.subCommentsNumber(blog_id);
    }
}
